package leetcode._1;

import java.util.Arrays;

public class Solution {

	public static void main(String[] args) {
		Solution s = new Solution();
		
		System.out.println(Arrays.toString(s.twoSum(new int[] { 6, 5, 7, 8, 9, 3 }, 10))); // [2, 5]

		System.out.println(Arrays.toString(s.twoSum(new int[] { 2, 7, 11, 15 }, 9))); // [0, 1]

		System.out.println(Arrays.toString(s.twoSum(new int[] { 3, 2, 4 }, 6))); // [1, 2]

		System.out.println(Arrays.toString(s.twoSum(new int[] { 3, 3 }, 6))); // [0, 1]
	}

	public int[] twoSum(int[] nums, int target) {
		for (int i = 0; i < nums.length; i++) {
			int idx = index(nums, i + 1, target - nums[i]);
			if (idx != -1) {
				return new int[] { i, idx };
			}
		}
		return new int[] { -1, -1 };
	}

	private int index(int[] nums, int startIndex, int n) {
		for (int i = startIndex; i < nums.length; i++) {
			if (nums[i] == n) {
				return i;
			}
		}
		return -1;
	}

}
